package com.cema.manage.project.manage.userFeedback.controller;
import java.util.ArrayList;
import java.util.List;

import cn.hutool.core.util.StrUtil;
import com.cema.manage.common.utils.StringUtils;
import com.cema.manage.framework.web.domain.BaseEntity;
import com.cema.manage.project.manage.userFeedback.domain.UserFeedback;
import com.cema.manage.project.manage.userFeedback.service.IUserFeedbackService;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.cema.manage.framework.web.controller.BaseController;
import com.cema.manage.framework.web.domain.Message;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.cema.manage.framework.web.page.TableDataInfo;


/**
 * 问题反馈 信息操作处理
 *
 * @author reasahi
 * @date 2024-07-11
 */
@Controller
@RequestMapping("/manage/userFeedback")
public class UserFeedbackController extends BaseController {
    private String prefix = "manage/userFeedback";

    @Autowired
    private IUserFeedbackService userFeedbackService;

    @GetMapping()
    @RequiresPermissions("manage:userFeedback:view")
    public String userFeedback() {
        return prefix + "/userFeedback";
    }

    /**
     * 查询问题反馈列表
     */
    @RequiresPermissions("manage:userFeedback:list")
    @ResponseBody
    @GetMapping("/list")
    public TableDataInfo list(BaseEntity entity) {
        startPage();
        EntityWrapper entityWrapper = new EntityWrapper();
        String value = entity.getSearchValue();
        if(StrUtil.isNotEmpty(value)){
            entityWrapper.eq("us_id",entity.getSearchValue());
        }
        List<UserFeedback> list = userFeedbackService.selectList(entityWrapper);
        return getDataTable(list);
    }

    /**
     * 新增问题反馈
     */
    @RequiresPermissions("manage:userFeedback:add")
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 修改问题反馈
     */
    @RequiresPermissions("manage:userFeedback:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, Model model) {
        UserFeedback userFeedback =userFeedbackService.selectById(id);
        model.addAttribute("userFeedback", userFeedback);
        return prefix + "/edit";
    }

    /**
     * 保存问题反馈
     */
    @RequiresPermissions("manage:userFeedback:save")
    @PostMapping("/save")
    @ResponseBody
    public Message save(UserFeedback userFeedback) {
        Integer id = userFeedback.getId();
        if (StringUtils.isNotNull(id)) {
            if (userFeedbackService.updateById(userFeedback)) {
                return Message.success();
            }
            return Message.error();
        } else {
            if (userFeedbackService.insert(userFeedback)) {
                return Message.success();
            }
            return Message.error();
        }
    }

    /**
     * 删除问题反馈
     */
    @RequiresPermissions("manage:userFeedback:remove")
    @PostMapping("/remove/{id}")
    @ResponseBody
    public Message remove(@PathVariable("id") Integer id) {
        if (userFeedbackService.deleteById(id)) {
            return Message.success();
        }
        return Message.error();
    }

    /**
     * 批量删除问题反馈
     */
    @RequiresPermissions("manage:userFeedback:batchRemove")
    @PostMapping("/batchRemove")
    @ResponseBody
    public Message remove(@RequestParam("ids[]") Integer[]ids) {
        List list = new ArrayList();
        for (Integer n:ids) {
            list.add(n);
        }
        if (userFeedbackService.deleteBatchIds(list)) {
            return Message.success();
        }
        return Message.error();
    }

}
